<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/17
 * Time: 13:01
 */

namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\facade\Db;
use think\facade\View;
use think\facade\Filesystem;

class content extends AdminBase
{
    //分类添加
    public function content_add()
    {
        $data = Db::name('content')->where('id',2)->find();
        if ($this->request->isPost()) {
            $param = input('post.');
            $param['update_time'] =time();
            $param['uid'] = session('admin_auth.admin_id');

            if($data['id']){
                $book = \app\common\model\Content::find($data['id']);
            }else{
                $param['create_time'] = time();
                $book = new \app\common\model\Content();
            }

            $msg = $book->allowfield([])->save($param);
            if($msg){
                $this->success('编辑成功');
            }else{
                $this->error('编辑失败');
            }
        }

        $map =[];
        if($data){
            $map['data'] = $data;
        }
        return $this->fetch('content_edit',$map);
    }

}